# 查找并加载protobuf和gRPC的CMake配置文件
find_package(protobuf CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)

# 查找c-ares库，是gRPC的依赖项
find_package(c-ares CONFIG)
# find_package(Threads)

set(PROTO_FILES
    monitor_info.proto
    cpu_load.proto
    cpu_softirq.proto
    cpu_stat.proto
    mem_info.proto
    net_info.proto
)


add_library(monitor_proto ${PROTO_FILES})

# 指定monitor_proto库需要链接的库
target_link_libraries(monitor_proto
    PUBLIC
        protobuf::libprotobuf
        gRPC::grpc
        gRPC::grpc++
)

# 指定monitor_proto库所需头文件的搜索路径
target_include_directories(monitor_proto PUBLIC
${PROTOBUF_INCLUDE_DIRS} 
${CMAKE_CURRENT_BINARY_DIR})

# 获取proto的grpc插件
get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION)

# 把库monitor_proto生成 .pb.h  .pb.cc
protobuf_generate(TARGET monitor_proto LANGUAGE cpp)
# 生成 .grpc.pb.h  .grpc.pb.cc
protobuf_generate(TARGET monitor_proto LANGUAGE grpc GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc PLUGIN "protoc-gen-grpc=${grpc_cpp_plugin_location}")
